package tabandfab.zjitc.net.androidpractisetabandfab;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private TabLayout mTabLayout;
    private Toolbar mToolbar;
    ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setSupportActionBar(mToolbar);
        init();
        initView();
        initRecycle();
    }

    private void initRecycle() {

    }


    private void init() {
        mTabLayout = findViewById(R.id.tab);
        mToolbar = findViewById(R.id.tool);
        viewPager = findViewById(R.id.viewpager);
    }

    private void initView() {
        List<String> titles = new ArrayList<>();
        titles.add("精选");
        titles.add("体育");
        titles.add("动漫");
        titles.add("精选");
        for (int i = 0; i < titles.size(); i++) {
            mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(i)));
        }
        List<View> list = new ArrayList<>();
        View view1 = getLayoutInflater().inflate(R.layout.view1, null, false);
        View view2 = getLayoutInflater().inflate(R.layout.view2, null, false);
        View view3 = getLayoutInflater().inflate(R.layout.view3, null, false);
        View view4 = getLayoutInflater().inflate(R.layout.view4, null, false);

        list.add(view1);
        list.add(view2);
        list.add(view3);
        list.add(view4);
        MyPagerAdapter myPagerAdapter = new MyPagerAdapter(titles, list);
        viewPager.setAdapter(myPagerAdapter);
        mTabLayout.setupWithViewPager(viewPager);


    }
}
